﻿using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Oragon.Architecture.Data.SqlBuilder;
using Oragon.Architecture.Data.SqlBuilder.Operators;
using Oragon.Architecture.Data.QueryBuilder.SqlServer;

namespace Oragon.Architecture.Data.QueryBuilder.Tests
{
	public class ex1
	{
		public virtual string Test()
		{
			return "ex1";
		}
	}

	public class ex2 : ex1
	{
		public override string Test()
		{
			return "ex2";
		}
	}

	public class ex3 : ex2
	{
		public override string Test()
		{
			return "ex3";
		}
	}

	[TestFixture]
	public class WhereClauseTest
	{
		[Test]
		public void OverridesAll()
		{
			List<ex1> items = new List<ex1>();
			items.Add(new ex1());
			items.Add(new ex2());
			items.Add(new ex3());

			foreach (ex1 ex in items)
			{
				string result = ex.Test();
				Console.WriteLine(result);
			}
		}


		[Test]
		public void TesteAll()
		{
			WhereClause whereClause = new WhereClause();
			whereClause.Items.Add(
				new AndBinaryOperator(
					LiteralManager.GetLiteralBuilder().BuildColumnName("ColunaA"),
					LiteralManager.GetLiteralBuilder().BuildColumnName("ColunaB")
				)
			);

			whereClause.Items.Add(
				new BetweenOperator(
					LiteralManager.GetLiteralBuilder().BuildColumnName("ColunaC"),
					LiteralManager.GetLiteralBuilder().BuildInt(10),
					LiteralManager.GetLiteralBuilder().BuildInt(20)
				)
			);

			whereClause.Items.Add(
				new DifferentOperator(
					LiteralManager.GetLiteralBuilder().BuildColumnName("ColunaA"),
					LiteralManager.GetLiteralBuilder().BuildColumnName("ColunaC")
				)
			);

			whereClause.Items.Add(
				new EqualToOperator(
					LiteralManager.GetLiteralBuilder().BuildColumnName("ColunaA"),
					LiteralManager.GetLiteralBuilder().BuildColumnName("ColunaC")
				)
			);

			whereClause.Items.Add(
				new GreaterThanOperator(
					LiteralManager.GetLiteralBuilder().BuildColumnName("ColunaA"),
					LiteralManager.GetLiteralBuilder().BuildColumnName("ColunaC")
				)
			);

			whereClause.Items.Add(
				new GreaterThanOrEqualToOperator(
					LiteralManager.GetLiteralBuilder().BuildColumnName("ColunaA"),
					LiteralManager.GetLiteralBuilder().BuildColumnName("ColunaC")
				)
			);

			whereClause.Items.Add(
				new IsNotNullOperator(
					LiteralManager.GetLiteralBuilder().BuildColumnName("ColunaA")
				)
			);

			whereClause.Items.Add(
				new IsNullOperator(
					LiteralManager.GetLiteralBuilder().BuildColumnName("ColunaC")
				)
			);

			whereClause.Items.Add(
				new LessThanOperator(
					LiteralManager.GetLiteralBuilder().BuildColumnName("ColunaA"),
					LiteralManager.GetLiteralBuilder().BuildColumnName("ColunaC")
				)
			);

			whereClause.Items.Add(
				new LessThanOrEqualToOperator(
					LiteralManager.GetLiteralBuilder().BuildColumnName("ColunaA"),
					LiteralManager.GetLiteralBuilder().BuildColumnName("ColunaC")
				)
			);

			whereClause.Items.Add(
				new LikeToOperator(
					LiteralManager.GetLiteralBuilder().BuildColumnName("ColunaA"),
					LiteralManager.GetLiteralBuilder().BuildParameter("ColunaC")
				)
			);

			whereClause.Items.Add(
				new OrBinaryOperator(
					LiteralManager.GetLiteralBuilder().BuildColumnName("ColunaA"),
					LiteralManager.GetLiteralBuilder().BuildParameter("ColunaC")
				)
			);

			whereClause.Items.Add(
				new AndUnaryOperator(
					LiteralManager.GetLiteralBuilder().BuildParameter("ColunaC")
				)
			);

			whereClause.Items.Add(
				new NotOperator(
					LiteralManager.GetLiteralBuilder().BuildParameter("ColunaC")
				)
			);

			whereClause.Items.Add(
				new OrUnaryOperator(
					LiteralManager.GetLiteralBuilder().BuildParameter("ColunaC")
				)
			);
			
			Assert.AreEqual(whereClause.ToSQL().Trim(), Oragon.Architecture.Data.QueryBuilder.Tests.Properties.Resources.WhereClauseTest_TesteAll);
		}

	}
}
